﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Caching;
using AresCustomYacht.Code;
using AresCustomYacht.Data;
using AresCustomYacht.DataContract;
using Task = AresCustomYacht.Code.Task;

namespace AresCustomYacht
{
    public class DAL
    {

        public  List<Summary>  GetCostSummaryReport(int boatId, List<int> workIds )
        {
            //using (var dc = new DBDataContext(Constants.ConnectionString))
            //{
            //    var trackings = dc.Trackings.Where(p => p.BoatId == boatId && workIds.Contains(p.TaskId)).ToList();
            //    var works = dc.Works.Where(p=> workIds.Contains(p.WorkId)).ToList();

            //    var summaryList = trackings.Select(summaryItem => new Summary
            //    {
            //        Id = summaryItem.TrackingId,
            //        TaskName  =
            //            works.First(
            //                p => p.WorkId == summaryItem.TaskId)
            //            .Location + "  " + works.First(
            //                p => p.WorkId == summaryItem.TaskId )
            //            .TaskDetail,
            //        BudgetHrs =
            //            Convert.ToDecimal(summaryItem.BudgetHrs),
            //        BudgetLabor =
            //            Convert.ToDecimal(
            //                summaryItem.BudgetLabor),
            //        BudgetMaterial =
            //            Convert.ToDecimal(
            //                summaryItem.BudgetMaterial),
            //    }).ToList();

            //    return summaryList;
            //}

            return null; 

        }

        public List<Task> GetDivisionTasks(int divisionId)
        {
            //TODO: you can cach these work tables in the class - use the cache class
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {

                var tradeIds = dc.Trades.Where(p => p.DivisionId == divisionId).Select(p => p.Id).ToList();
                var locationIds = dc.Locations.Where(p => tradeIds.Contains(p.TradeId )).Select(p => p.Id).ToList();
                return dc.Tasks.Where(p => locationIds.Contains(p.LocationId)).ToList();

            }
        }

        public List<int> GetTradesTasks(List<int> tradeIds )
        {
            //TODO: you can cach these work tables in the class - use the cache class
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {

 
                var locationIds = dc.Locations.Where(p => tradeIds.Contains(p.TradeId)).Select(p => p.Id).ToList();
                return  dc.Tasks.Where(p => locationIds.Contains(p.LocationId)).Select(p => p.Id).ToList();

            }
        }

        public List<Trade> GetDivisionTrades(int divisionId)
        {
            //TODO: you can cach these work tables in the class - use the cache class
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                return dc.Trades.Where(p => p.DivisionId == divisionId).ToList();
            }
        }

        public List<Location> GetTradesLocations(List<Trade> trades)
        {
            //TODO: you can cach these work tables in the class - use the cache class
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                return dc.Locations.Where(p => trades.Select(x=> x.Id).Contains(p.TradeId )).ToList();
            }
        }

        public List<Location> GetTradesLocations(List<int> tradeIds)
        {
            //TODO: you can cach these work tables in the class - use the cache class
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                return dc.Locations.Where(p => tradeIds.Contains(p.TradeId)).ToList();
            }
        }

        public List<Task> GetLocationsTasks(List<Location> locations)
        {
            //TODO: you can cach these work tables in the class - use the cache class
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                return dc.Tasks.Where(p => locations.Select(x => x.Id).Contains(p.LocationId)).ToList();
            }
        }

        public List<Trade> GetLocationsTrades(List<Location> locations)
        {
            //TODO: you can cach these work tables in the class - use the cache class
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                var tradeIds = locations.Select(p => p.TradeId).Distinct().ToList();
                return dc.Trades.Where(p => tradeIds.Contains(p.Id)).ToList();
            }
        }

        public List<Task> GetLocationsTasks(int locationId)
        {

            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                return dc.Tasks.Where(p => p.LocationId == locationId).ToList();
            }
        }


        public List<Summary> GetCostDetailByLocation(int boatId, string locationString)
        {

            List<Summary> output = new List<Summary>();

            //TODO: Cache all of these and in the application object make sure to load the cach everytime a class or ADT reference is added. Also check how to use Cach object

            var workLocations = GetLocationsByString(locationString); //all locations connected with those trades
            var workTasks = GetLocationsTasks(workLocations); //all tasks connected with those locations
            var workTrades = GetLocationsTrades(workLocations); //all Id's for metalwork for example. They can span multiple divisions
            var workDivisions = GetDivisions(); //since divisions are little just get all of them

            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                //this is the report data. We need to merge the report data with Divisions, Locations and tasks
                var trackings = dc.Trackings.Where(p => p.BoatId == boatId && workTasks.Select(x => x.Id).Contains(p.TaskId)).ToList(); //trackings for the report

                var denormalizedTrackings = DenormalizeTracking(trackings, workTasks, workLocations, workTrades, workDivisions).Where(p=> p !=null).ToList();

                output.Add(new Summary
                {
                    BudgetRate = denormalizedTrackings.Sum(p => p.BudgetRate),
                    BudgetHrs = denormalizedTrackings.Sum(p => p.BudgetHrs),
                    ActualRate = denormalizedTrackings.Sum(p => p.ActualRate),
                    ActualHrs = denormalizedTrackings.Sum(p => p.ActualHrs),
                    ActualMaterial = denormalizedTrackings.Sum(p => p.ActualMaterial),
                    BudgetMaterial = denormalizedTrackings.Sum(p => p.BudgetMaterial),
                    cssClass = "GrandTotal",

                });

                //Group by DivisionId and get total for each divisio
                foreach (var division in workDivisions.Select(p => p.Id).Distinct())
                {
                    var divisionId = division;
                    var divisionsToProcess = denormalizedTrackings.Where(p => p.DivisionId == divisionId);
                    if (divisionsToProcess.Any())
                        output.AddRange(ProcessDivisionsFollowedByTrade(divisionsToProcess, workTrades, workLocations, workTasks));
                }



            }
            return output;


        }

        public List<Summary> GetCostDetailByTrade(int boatId, string tradeString)
        {

            var output = new List<Summary>();

            //TODO: Cache all of these and in the application object make sure to load the cach everytime a class or ADT reference is added. Also check how to use Cach object
            var workTrades = GetTradesByString(tradeString); //all Id's for metalwork for example. They can span multiple divisions

            var workLocations = GetTradesLocations(workTrades); //all locations connected with those trades
            var workTasks = GetLocationsTasks(workLocations); //all tasks connected with those locations
            var workDivisions = GetDivisions(); //since divisions are little just get all of them

            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                //this is the report data. We need to merge the report data with Divisions, Locations and tasks
                var trackings = dc.Trackings.Where(p => p!= null &&  p.BoatId == boatId && workTasks.Select(x=> x.Id).Contains(p.TaskId)).ToList(); //trackings for the report

                var denormalizedTrackings = DenormalizeTracking(trackings, workTasks, workLocations, workTrades, workDivisions).Where(p=> p!= null).ToList();

                output.Add(new Summary
                               {
                                   BudgetRate = 0m,
                                   BudgetHrs = denormalizedTrackings.Sum(p => p.BudgetHrs),

                                   ActualRate = 0m,
                                   ActualHrs = denormalizedTrackings.Sum(p => p.ActualHrs),

                                   ActualMaterial  = denormalizedTrackings.Sum(p=> p.ActualMaterial),
                                   BudgetMaterial  = denormalizedTrackings.Sum(p=> p.BudgetMaterial),
                                   ActualTotal = denormalizedTrackings.Sum(p=> p.ActualTotal),
                                   BudgetTotal = denormalizedTrackings.Sum(p => p.BudgetTotal),
                                   //Need to calculate Actual Total and Budget Total for the summary based on the line items
                                  
                                   cssClass = "GrandTotal",

                               });

                //Group by DivisionId and get total for each divisio
                foreach (var division in workDivisions.Select(p=> p.Id).Distinct())
                {
                    int division1 = division;
                    var divisionsToProcess = denormalizedTrackings.Where(p => p.DivisionId == division1);
                    if (divisionsToProcess.Any())
                        output.AddRange(ProcessDivisionsFollowedByLocation(divisionsToProcess, workLocations, workTasks));
                }



            }
            return output;
            

        }

        private IEnumerable<Summary> ProcessDivisionsFollowedByLocation(IEnumerable<Summary> divisionData, List<Location> workLocations, List<Task> workTasks)
        {


            if (!divisionData.Any()) return null;

            var output = new List<Summary>();


            int i = 0;

            var firstRecord = divisionData.First();
            var divisionTotal = new Summary
                             {
                                 Code = firstRecord.DivisionCode,
                                 DisplayOrder = i++,
                                 Description = firstRecord.DivisionName,
                                 BudgetMaterial = divisionData.Sum(p => p.BudgetMaterial),
                                 BudgetHrs = divisionData.Sum(p => p.BudgetHrs),
                                 BudgetRate = 0m,
                                 ActualHrs = divisionData.Sum(p => p.ActualHrs),
                                 ActualRate = 0m,
                                 ActualMaterial = divisionData.Sum(p => p.ActualMaterial),
                                 ActualTotal = divisionData.Sum(p => p.ActualTotal),
                                 BudgetTotal = divisionData.Sum(p => p.BudgetTotal),

                                 DivisionId = firstRecord.DivisionId,
                                 DivisionCode = firstRecord.DivisionCode,
                                 DivisionName = firstRecord.DivisionName,
                                 cssClass = "DivisionTotal",
                             };


            output.Add(divisionTotal);
            //For this division Process Locations 
            foreach(var location in workLocations.Select(p=> p.Id).Distinct())
            {
                int locationId = location;
                var locationsToProcess = divisionData.Where(p => p.LocationId == locationId);
                if (locationsToProcess.Any())
                    output.AddRange(ProcessLocationFollowedByTask(locationsToProcess, workTasks) );
            }
            return output;


        }

        private IEnumerable<Summary> ProcessDivisionsFollowedByTrade(IEnumerable<Summary> divisionData, List<Trade> workTrades, List<Location> workLocations, List<Task> workTasks )
        {


            if (!divisionData.Any()) return null;

            var output = new List<Summary>();


            int i = 0;

            var firstRecord = divisionData.First();
            var divisionTotal = new Summary
            {
                Code = firstRecord.DivisionCode,
                DisplayOrder = i++,
                Description = firstRecord.DivisionName,
                BudgetMaterial = divisionData.Sum(p => p.BudgetMaterial),
                BudgetHrs = divisionData.Sum(p => p.BudgetHrs),
                ActualRate = divisionData.Sum(p => p.ActualRate),
                ActualHrs = divisionData.Sum(p => p.ActualHrs),
                ActualMaterial = divisionData.Sum(p => p.ActualMaterial),
                BudgetRate = divisionData.Sum(p => p.BudgetRate),

                DivisionId = firstRecord.DivisionId,
                DivisionCode = firstRecord.DivisionCode,
                DivisionName = firstRecord.DivisionName,
                cssClass = "DivisionTotal",
            };

            output.Add(divisionTotal);
            //For this division Process Locations 
            foreach (var trade in workTrades.Select(p => p.Id).Distinct())
            {
                int tradeId = trade;
                var tradesToProcess = divisionData.Where(p => p.TradeId == tradeId);
                if (tradesToProcess.Any())
                    output.AddRange(ProcessTradeFollowedByTask(tradesToProcess, workTasks));
            }
            return output;


        }

        private IEnumerable<Summary> ProcessTradeFollowedByLocation(IEnumerable<Summary> tradesData,  List<Location> workLocations, List<Task> workTasks )
        {
            if (!tradesData.Any()) return null;

            var output = new List<Summary>();
            var firstRecord = tradesData.First();
            var tradeTotal = new Summary
            {
                Code = firstRecord.DivisionCode + "-" + firstRecord.TradeCode,
                Description = firstRecord.TradeName,
                BudgetMaterial = tradesData.Sum(p => p.BudgetMaterial),
                BudgetHrs = tradesData.Sum(p => p.BudgetHrs),
                ActualHrs = tradesData.Sum(p => p.ActualHrs),
                ActualMaterial = tradesData.Sum(p => p.ActualMaterial),
                BudgetRate = tradesData.Sum(p => p.BudgetRate),
                ActualRate = tradesData.Sum(p => p.ActualRate),

                DivisionId = firstRecord.DivisionId,
                DivisionCode = firstRecord.DivisionCode,
                DivisionName = firstRecord.DivisionName,
                cssClass = "TradeTotal",
            };

            output.Add(tradeTotal);
            //For this division Process Locations 
            foreach (var location in workLocations.Select(p => p.Id).Distinct())
            {
                int locationId = location;
                var locationsToProcess = tradesData.Where(p => p.LocationId == locationId);
                if (locationsToProcess.Any())
                    output.AddRange(ProcessLocationFollowedByTask(locationsToProcess, workTasks));
            }
            return output;
        }



        private IEnumerable<Summary> ProcessTradeFollowedByTask(IEnumerable<Summary> tradesData, List<Task> workTasks)
        {
            if (!tradesData.Any()) return null;

            var output = new List<Summary>();
            var firstRecord = tradesData.First();
            var tradeTotal = new Summary
            {
                Code = firstRecord.DivisionCode + "-" + firstRecord.TradeCode,
                Description = firstRecord.TradeName,
                BudgetMaterial = tradesData.Sum(p => p.BudgetMaterial),
                BudgetHrs = tradesData.Sum(p => p.BudgetHrs),
                ActualHrs = tradesData.Sum(p => p.ActualHrs),
                ActualMaterial = tradesData.Sum(p => p.ActualMaterial),
                BudgetRate = tradesData.Sum(p => p.BudgetRate),
                ActualRate = tradesData.Sum(p => p.ActualRate),

                DivisionId = firstRecord.DivisionId,
                DivisionCode = firstRecord.DivisionCode,
                DivisionName = firstRecord.DivisionName,
                cssClass = "TradeTotal",
            };

            output.Add(tradeTotal);
            //For this division Process Locations 
            foreach (var task in workTasks.Select(p => p.Id).Distinct())
            {
                int taskId = task;
                var tasksToProcess = tradesData.Where(p => p.TaskId == taskId);
                if (tasksToProcess.Any())
                    output.AddRange(ProcessTask(tasksToProcess));
            }
            return output;
        }



        private IEnumerable<Summary> ProcessLocationFollowedByTask(IEnumerable<Summary> locationData, List<Task> workTasks)
        {


            if (!locationData.Any()) return null;

            var output = new List<Summary>();

            var firstRecord = locationData.First();

            var locationTotal = new Summary
            {
                Code = firstRecord.DivisionCode + "-" + firstRecord.TradeCode + "-" + firstRecord.LocationCode,
                Description =  firstRecord.LocationName,
                BudgetMaterial = locationData.Sum(p => p.BudgetMaterial),
                BudgetHrs = locationData.Sum(p => p.BudgetHrs),
                ActualHrs = locationData.Sum(p => p.ActualHrs),
                ActualMaterial = locationData.Sum(p => p.ActualMaterial),
                BudgetRate = 0m,
                ActualRate = 0m,
                ActualTotal = locationData.Sum(p => p.ActualTotal),
                BudgetTotal = locationData.Sum(p => p.BudgetTotal),
                cssClass = "LocationTotal",
            };



            output.Add(locationTotal);
            //For this division Process Locations 
            foreach (var task in workTasks.Select(p => p.Id).Distinct())
            {
                int taskId = task;
                var tasksToProcess = locationData.Where(p => p.TaskId == taskId);
                if (tasksToProcess.Any())
                    output.AddRange(ProcessTask(tasksToProcess));
            }
            return output;
        }

        private List<Summary> ProcessTask(IEnumerable<Summary> taskData)
        {
            
            if (!taskData.Any()) return null;
            var output = taskData.ToList();
            output.ForEach(p =>
                               {
                                   p.Description = p.TaskDescription;
                                   p.Code = p.DivisionCode + "-" + p.TradeCode + "-" + p.LocationCode + "-" + p.TaskCode;
                                   p.cssClass = "Task";
                               });
            return output;
        }

        private IEnumerable<Summary> DenormalizeTracking(IEnumerable<Tracking> trackings, IEnumerable<Task> workTasks, IEnumerable<Location> workLocations, IEnumerable<Trade> workTrades, IEnumerable<Division> workDivisions)
        {
            var output = new List<Summary>();

            Parallel.ForEach(trackings, p =>
                                  {
                                      var thisTask = workTasks.First(t => t.Id == p.TaskId);
                                      var thisLocation = workLocations.First(t => t.Id == thisTask.LocationId);
                                      var thisTrade = workTrades.First(t => t.Id == thisLocation.TradeId);
                                      var thisDivision = workDivisions.First(t => t.Id == thisTrade.DivisionId);


                                      output.Add(new Summary
                                                     {
                                                         TaskId = p.TaskId,
                                                         //Budget
                                                         BudgetHrs = p.BudgetHrs??0m,
                                                         BudgetRate = p.BudgetRate ?? 0m,
                                                         BudgetMaterial = p.BudgetMaterial ?? 0m,


                                                         //Actual
                                                         ActualMaterial = p.ActualMaterial??0m,
                                                         ActualHrs = p.ActualHrs ?? 0m ,
                                                         ActualRate = p.ActualRate ?? 0m,
                                                         InvoiceRate = p.InvoiceRate ?? 0m,
                                                         InvoiceMaterialPercentage = p.InvoiceMaterialPercent ?? 0m,

                                                         TaskDescription = p.TaskDescription,
                                                         TaskCode = thisTask.Code,
                                                         TaskName = thisTask.Name,
                                                         TrackId = p.TrackingId,
                                                         LocationId = thisLocation.Id,
                                                         LocationCode =thisLocation.Code,
                                                         LocationName = thisLocation.Name,
                                                         TradeId = thisTrade.Id,
                                                         TradeCode = thisTrade.Code,
                                                         TradeName = thisTrade.Name,
                                                         DivisionId = thisDivision.Id,
                                                         DivisionCode = thisDivision.Code,
                                                         DivisionName = thisDivision.Name ,
                                                         cssClass = "Task",

                                                     });
                                  });
            return output;
        }

        private List<Trade> GetTrades(List<int> tradeIds)
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                return dc.Trades.Where(p => tradeIds.Contains(p.Id)).ToList();
            }
        }



        public List<int> GetTradeId(string tradeString)
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                return dc.Trades.Where(p => p.Name.ToUpper() == tradeString.ToUpper()).Select(x=> x.Id).ToList();
            }
        }

        public List<Trade> GetTradesByString(string tradeString)
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                return dc.Trades.Where(p => tradeString.ToUpper() == p.Name.ToUpper()).ToList();
            }
        }

        public List<Location> GetLocationsByString(string locationString)
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                return dc.Locations.Where(p => locationString.ToUpper() == p.Name.ToUpper()).ToList();
            }
        }

        public List<DataContract.Boat> GetBoats()
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                return dc.Boats.Select(p=> new DataContract.Boat{Id= p.BoatId, Name= p.BoatName, OwnerId = (Guid) p.OwnerId}).ToList();
            }
        }

        internal void AddTracking(Tracking tracking)
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                dc.Trackings.InsertOnSubmit(tracking);
                dc.SubmitChanges();
            }
        }

        internal Code.Boat GetBoat(Guid userId)
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                return  dc.Boats.First(p => p.OwnerId == userId);
                
            }
        }

        internal Code.Boat GetBoat(int boatId)
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                return dc.Boats.First(p => p.BoatId == boatId);

            }
        }

        internal ReportDetail GetReportDetail(int reportDetailId)
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                return dc.ReportDetails.First(p => p.ReportDetailId == reportDetailId);
            }
        }

        internal List<Division> GetDivisions()
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                return dc.Divisions.OrderBy(p=> p.Code).ToList();
            }
        }


        internal List<int> GetTradesDivisions(List<int> tradeIds )
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                return   dc.Trades.Where(p=> tradeIds.Contains(p.Id)).Select(x=> x.DivisionId).ToList();
            }
        }

        internal List<Location> GetTradeLocations(int departmentId)
        {
            
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                return dc.Locations.Where(p => p.TradeId  == departmentId).ToList();
            }
        }

        internal Task GetTask(int taskId)
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                return dc.Tasks.First(p=> p.Id == taskId);
            }
        }

        internal void UpdateTracking(int trackId, Tracking actualCost)
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                var existingCost = dc.Trackings.First(p => p.TrackingId == trackId);
                ReflectionCopier<Tracking>.Copy(actualCost, existingCost);
                existingCost.TaskId = actualCost.TaskId;
                dc.SubmitChanges();

            }
        }

        internal Tracking GetTrack(int trackId)
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                return dc.Trackings.First(p => p.TrackingId == trackId);
            }
        }

        internal void AddBoat(string boatName, Guid ownerId)
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                var boat = new Code.Boat {BoatName = boatName, OwnerId = ownerId};

                dc.Boats.InsertOnSubmit(boat);
                dc.SubmitChanges();

            }
        }

        internal void AddDivisions(Dictionary<string, string> divisions)
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                var cats = new List<Division>();

                foreach(var division in divisions)
                {
                    var oneDivision = new Code.Division() {Code = division.Key, Name = division.Value};
                    cats.Add(oneDivision);
                }
                dc.Divisions.InsertAllOnSubmit(cats);
                dc.SubmitChanges();

            }
        }

        internal void AddDepartments(int parentId, Dictionary<string, string> dataDictionary)
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                var rows = new List<Trade>();

                foreach (var row in dataDictionary)
                {
                    var workDepartment = new Code.Trade() { Code = row.Key, Name = row.Value, DivisionId  = parentId };
                    rows.Add(workDepartment);
                }
                dc.Trades.InsertAllOnSubmit(rows);
                dc.SubmitChanges();

            }
        }

        internal void AddLocations(int parentId, Dictionary<string, string> dataDictionary)
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                var rows = new List<Location>();

                foreach (var row in dataDictionary)
                {
                    var workLocation = new Code.Location()  { Code = row.Key, Name = row.Value, TradeId = parentId };
                    rows.Add(workLocation);
                }
                dc.Locations.InsertAllOnSubmit(rows);
                dc.SubmitChanges();

            }
        }

        internal void AddTasks(int parentId, Dictionary<string, string> dataDictionary)
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                var rows = new List<Task>();

                foreach (var row in dataDictionary)
                {
                    var workType = new Code.Task() { Code = row.Key, Name = row.Value, LocationId = parentId };
                    rows.Add(workType);
                }
                dc.Tasks.InsertAllOnSubmit(rows);
                dc.SubmitChanges();

            }
        }



        internal List<ReportDetail> GetReportDetails()
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                return dc.ReportDetails.ToList();

            }
        }

        internal List<Report> GetReports()
        {
            using (var dc = new DBDataContext(Constants.ConnectionString))
            {
                return dc.Reports.ToList();

            }
        }
    }
}